﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure;
using System.Reflection;

namespace SeanBDD
{
    public delegate void Submit<T>(T command) where T : Command;

    public class CommandSpecification
    {
        public Func<Command> Command { get; set; }
        public Dictionary<String, Type> WillPublish { get; set; }
    }

    public interface ISpecification
    {
    }

    public class Runner
    {

        public static void RunTests(Assembly assembly)
        {
            foreach (Type x in assembly.GetTypes())
            {
                Object spec;
                spec = Activator.CreateInstance(x);

                foreach (FieldInfo y in x.GetFields())
                {
                
                    dynamic command = null;
                    dynamic events;

                    if (y.FieldType == typeof(CommandSpecification))
                    {                        
                        FieldInfo field = spec.GetType().GetField(y.Name);
                        command = field.GetValue(spec);                        
                    }

                    if (y.FieldType == typeof(Dictionary<String, Type>))
                    {                    
                        FieldInfo field = spec.GetType().GetField(y.Name);
                        //command = field.GetValue(spec);
                    }

                    command.Command();
                }

            }
        }
    }

}
